﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _180FrameWork.CustControls.Models;
//using _180FrameWork.Common;

namespace _180FrameWork.CustControls
{
    public partial class CustPagination : UserControl
    {
        private bool _IsPaging = true;
        public bool IsPaging
        {
            get { return this._IsPaging; }
            set
            {
                this._IsPaging = value;
                this.cbPageSize.Visible = this._IsPaging;
                this.btnFirst.Visible = this._IsPaging;
                this.btnLast.Visible = this._IsPaging;
                this.btnNext.Visible = this._IsPaging;
                this.btnPre.Visible = this._IsPaging;
                this.lb1.Visible = this._IsPaging;
                this.lbTotalPage.Visible = this._IsPaging;
                this.txtCurrentPage.Visible = this._IsPaging;
            }
        }
        public int PageSize
        {
            get { return int.Parse( this.cbPageSize.GetValue().ToString()); }
        }
        public int CurrentPage
        {
            get { return int.Parse(this.txtCurrentPage.Value.ToString()); }
            private set { this.txtCurrentPage.SetValue(value); }
        }
        private int _TotalPage = 1;
        public int TotalPage
        {
            get { return this._TotalPage; }
            private set
            {
                this._TotalPage = value;
                this.lbTotalPage.Text = string.Format("页/共{0}页", this._TotalPage);
            }
        }

        public CustPagination()
        {
            InitializeComponent();
            IList<KeyValueDict> dict = new List<KeyValueDict>();
            dict.Add(new KeyValueDict() { DM = "50", MC = "50" });
            dict.Add(new KeyValueDict() { DM = "100", MC = "100" });
            dict.Add(new KeyValueDict() { DM = "500", MC = "500" });
            dict.Add(new KeyValueDict() { DM = "1000", MC = "1000" });
            this.cbPageSize.DataSource = dict;
            this.cbPageSize.SelectedIndex = 1;

        }

        public void Init(int total)
        {
            //计算总共有多少页
            int t = (total / PageSize) + (total % PageSize == 0 ? 0 : 1);
            if (t <= 0)
                t = 1;
            TotalPage = t;
        }

        private void cbPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            CurrentPage = 1;
        }

        private void btnPre_Click(object sender, EventArgs e)
        {
            if (CurrentPage != 1)
                CurrentPage = CurrentPage - 1;
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (CurrentPage != TotalPage)
                CurrentPage = CurrentPage + 1;
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            CurrentPage = TotalPage;
        }

        private void CustPagination_Load(object sender, EventArgs e)
        {

        }
    }
}
